/*
 * Tezad - Classic puzzle game
 * Copyright 2009 Shayne Riley and Paul Maseberg
 *
 * Tezad is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tezad is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Tezad.  If not, see <http://www.gnu.org/licenses/>
 * or write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * To contact the authors on questions or issues regarding the license,
 * you may send an email to <pezads at gmail dot com>
 */

#include "Subject.h"

using std::list;

Subject::Subject() : observers() { /* do nothing */ }

Subject::~Subject() { /* do nothing */ }

void Subject::attach(Functor1<Command&> observer)
{
    observers.push_back(observer);
}

void Subject::detach(Functor1<Command&> observer)
{
    observers.remove(observer);
}

void Subject::notify(Command &command)
{
    std::list<Functor1<Command&> >::iterator oi = observers.begin();
    for ( ; oi != observers.end(); ++oi)
    {
        (*oi)(command);
    }
}
